import axios from 'axios'

const instance = axios.create({
  baseURL: '/',  // 配置公共的接口路径
  timeout: 1000 * 60
})

// 添加请求拦截器
instance.interceptors.request.use(config => {
  config.headers['ticket'] = 'xxx';
  return config;
}, error => {
  return Promise.reject(error);
});

// 添加响应拦截器
instance.interceptors.response.use(
  response => {
    if (response.data.success) {
      return response.data;
    } else {
      return Promise.reject(error);
    }
  },
  error => {
    return Promise.reject(error);
  }
)

export default instance;